package com.yangit.temp.util.mongodb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yangit.temp.util.mongodb.entity.MongoUser;
import com.yangit.temp.util.mongodb.service.MongoService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "mongodb模块说明 ") // 作用在模块类上
@ApiOperation("测试")
@RestController
public class MongoController {

	@Autowired
	private MongoService mtdao;

	@ApiOperation(value = "post请求调用示例", notes = "invokePost说明", httpMethod = "GET")
	@GetMapping(value = "/save")
	public void saveTest() throws Exception {
		MongoUser mgtest = new MongoUser();
		mgtest.setId(11);
		mgtest.setAge(33);
		mgtest.setName("ceshi");
		mtdao.saveTest(mgtest);
	}

	@GetMapping(value = "/find")
	public MongoUser findTestByName() {
		MongoUser mgtest = mtdao.findTestByName("ceshi");
		System.out.println("mgtest is " + mgtest);
		return mgtest;
	}

	@GetMapping(value = "/updt")
	public void updateTest() {
		MongoUser mgtest = new MongoUser();
		mgtest.setId(11);
		mgtest.setAge(44);
		mgtest.setName("ceshi2");
		mtdao.updateTest(mgtest);
	}

	@GetMapping(value = "/delt")
	public void deleteTestById() {
		mtdao.deleteTestById(11);
	}

}
